package qc.module.iot.protocol.sl651;

import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

/**
 * SL651 Ascii协议遥测站分类码，按附录A 表A.1中的定义
 *
 * @author QuCheng Tech
 * @since 2025/11/14
 */
@Getter
@AllArgsConstructor
public enum SL651_Ascii_FrameStationCategoryCodeEnum {
    UN_DEFINE(0, "未定义"),
    RAIN(0x50, "P"),
    RIVER(0x48, "H"),
    RESERVOIR(0x4B, "K"),//水库 湖泊
    GATE(0x5A, "Z"),
    PUMP(0x44, "D"),
    TIDE(0x54, "T"),
    MOISTURE(0x4D, "M"),
    GROUND(0x47, "G"),
    QUALITY(0x51, "Q"),
    INTAKE(0x49, "I"),
    OUTLET(0x4F, "O");

    @EnumValue
    private int index;
    private String name;

    @Override
    public String toString() {
        if (this != null)
            return this.name;

        return null;
    }

    /**
     * 根据int数值获取对应的枚举
     *
     * @param index 数值，限制为1字节
     * @return qc.module.iot.protocol.sl651.SL651_Ascii_FrameStationCategoryCodeEnum
     * @author QuCheng Tech
     * @since 2025/11/9
     */
    public static SL651_Ascii_FrameStationCategoryCodeEnum getSL651_FrameStationCategoryCodeEnum(int index) {
        if (index > 0x0) {
            int byteIntValue = index & 0xFF;//传入的值限制为1字节，最大0xFF
            if (byteIntValue > 0x0) {
                for (SL651_Ascii_FrameStationCategoryCodeEnum item : SL651_Ascii_FrameStationCategoryCodeEnum.values()) {
                    if (item.getIndex() == byteIntValue) {//判断序号使用getIndex，判断内容使用getName
                        return item;
                    }
                }
            }
        }
        return SL651_Ascii_FrameStationCategoryCodeEnum.UN_DEFINE;
    }

    /**
     * 根据int数值获取对应的枚举
     *
     * @param name 标识符Ascii码
     * @return qc.module.iot.protocol.sl651.SL651_IdentifierEnum
     * @author QuCheng Tech
     * @since 2025/11/14
     */
    public static SL651_Ascii_FrameStationCategoryCodeEnum getSL651_FrameStationCategoryCodeEnum(String name) {
        if (StringUtils.isNotBlank(name)) {
            for (SL651_Ascii_FrameStationCategoryCodeEnum item : SL651_Ascii_FrameStationCategoryCodeEnum.values()) {
                if (StringUtils.equalsIgnoreCase(name, item.getName())) {//判断序号使用getIndex，判断内容使用getName
                    return item;
                }
            }
        }
        return SL651_Ascii_FrameStationCategoryCodeEnum.UN_DEFINE;
    }
}
